<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article# " lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>fitting-a-line-through-data | 绿萝间</title>
<link href="../assets/css/all-nocdn.css" rel="stylesheet" type="text/css">
<link href="../assets/css/ipython.min.css" rel="stylesheet" type="text/css">
<link href="../assets/css/nikola_ipython.css" rel="stylesheet" type="text/css">
<meta name="theme-color" content="#5670d4">
<meta name="generator" content="Nikola (getnikola.com)">
<link rel="alternate" type="application/rss+xml" title="RSS" href="../rss.xml">
<link rel="canonical" href="https://muxuezi.github.io/posts/fitting-a-line-through-data.html">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
    },
    displayAlign: 'center', // Change this to 'center' to center equations.
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}}
    }
});
</script><!--[if lt IE 9]><script src="../assets/js/html5.js"></script><![endif]--><meta name="author" content="Tao Junjie">
<link rel="prev" href="optimizing-the-ridge-regression-parameter.html" title="optimizing-the-ridge-regression-parameter" type="text/html">
<link rel="next" href="evaluating-the-linear-regression-model.html" title="evaluating-the-linear-regression-model" type="text/html">
<meta property="og:site_name" content="绿萝间">
<meta property="og:title" content="fitting-a-line-through-data">
<meta property="og:url" content="https://muxuezi.github.io/posts/fitting-a-line-through-data.html">
<meta property="og:description" content="线性回归模型¶








现在，我们来做一些建模！我们从最简单的线性回归（Linear regression）开始。线性回归是最早的也是最基本的模型——把数据拟合成一条直线。









Getting ready¶








boston数据集很适合用来演示线性回归。boston数据集包含了波士顿地区的房屋价格中位数。还有一些可能会影响房价的因素，比如犯罪率（crime rat">
<meta property="og:type" content="article">
<meta property="article:published_time" content="2015-08-18T12:57:47+08:00">
<meta property="article:tag" content="CHS">
<meta property="article:tag" content="ipython">
<meta property="article:tag" content="Machine Learning">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="scikit-learn cookbook">
</head>
<body>
<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>

<!-- Menubar -->

<nav class="navbar navbar-inverse navbar-static-top"><div class="container">
<!-- This keeps the margins nice -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar" aria-controls="bs-navbar" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="https://muxuezi.github.io/">

                <span id="blog-title">绿萝间</span>
            </a>
        </div>
<!-- /.navbar-header -->
        <div class="collapse navbar-collapse" id="bs-navbar" aria-expanded="false">
            <ul class="nav navbar-nav">
<li>
<a href="../archive.html">Archive</a>
                </li>
<li>
<a href="../categories/">Tags</a>
                </li>
<li>
<a href="../rss.xml">RSS feed</a>

                
            </li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
    <a href="fitting-a-line-through-data.ipynb" id="sourcelink">Source</a>
    </li>

                
            </ul>
</div>
<!-- /.navbar-collapse -->
    </div>
<!-- /.container -->
</nav><!-- End of Menubar --><div class="container" id="content" role="main">
    <div class="body-content">
        <!--Body content-->
        <div class="row">
            
            
<article class="post-text h-entry hentry postpage" itemscope="itemscope" itemtype="http://schema.org/Article"><header><h1 class="p-name entry-title" itemprop="headline name"><a href="#" class="u-url">fitting-a-line-through-data</a></h1>

        <div class="metadata">
            <p class="byline author vcard"><span class="byline-name fn">
                    Tao Junjie
            </span></p>
            <p class="dateline"><a href="#" rel="bookmark"><time class="published dt-published" datetime="2015-08-18T12:57:47+08:00" itemprop="datePublished" title="2015-08-18 12:57">2015-08-18 12:57</time></a></p>
            
        <p class="sourceline"><a href="fitting-a-line-through-data.ipynb" id="sourcelink">Source</a></p>

        </div>
        

    </header><div class="e-content entry-content" itemprop="articleBody text">
    <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="线性回归模型">线性回归模型<a class="anchor-link" href="fitting-a-line-through-data.html#%E7%BA%BF%E6%80%A7%E5%9B%9E%E5%BD%92%E6%A8%A1%E5%9E%8B">¶</a>
</h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>现在，我们来做一些建模！我们从最简单的线性回归（Linear regression）开始。线性回归是最早的也是最基本的模型——把数据拟合成一条直线。</p>
<!-- TEASER_END -->
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Getting-ready">Getting ready<a class="anchor-link" href="fitting-a-line-through-data.html#Getting-ready">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>boston</code>数据集很适合用来演示线性回归。<code>boston</code>数据集包含了波士顿地区的房屋价格中位数。还有一些可能会影响房价的因素，比如犯罪率（crime rate）。</p>
<p>首先，让我们加载数据：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [1]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">datasets</span>
<span class="n">boston</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">load_boston</span><span class="p">()</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="How-to-do-it...">How to do it...<a class="anchor-link" href="fitting-a-line-through-data.html#How-to-do-it...">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>实际上，用scikit-learn的线性回归非常简单，其API和前面介绍的模型一样。</p>
<p>首先，导入<code>LinearRegression</code>类创建一个对象：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [2]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">sklearn.linear_model</span> <span class="k">import</span> <span class="n">LinearRegression</span>
<span class="n">lr</span> <span class="o">=</span> <span class="n">LinearRegression</span><span class="p">()</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>现在，再把自变量和因变量传给<code>LinearRegression</code>的<code>fit</code>方法：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [3]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lr</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[3]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>现在开始预测：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [4]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">predictions</span> <span class="o">=</span> <span class="n">lr</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>要看预测的效果，我们用预测值与实际值的残差（residuals）直方图分布来演示：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [5]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">matplotlib</span> inline
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="k">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="n">f</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
<span class="n">f</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="o">-</span><span class="n">predictions</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'Residuals Linear'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'b'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=.</span><span class="mi">5</span><span class="p">);</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"Histogram of Residuals"</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s1">'best'</span><span class="p">);</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="%0AAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucnVV97/HPL+FOCAGik3CJg1GKoBgsKrUqAwakETEF%0Ay0WgwePLvqwcajznVEE9dFJbAasvU1q02iKmIBfRCsg1OeAIoUKkEsRwiegZDiCZCGQIF0mC+Z0/%0A9pNxMpmZvSeZncma+bxfr/2a57L286xZycx31nqeZ+3ITCRJ0rZt3EhXQJIk1WdgS5JUAANbkqQC%0AGNiSJBXAwJYkqQAGtiRJBTCwNaZFxM8j4t0jXY+RFBF/GhGPR8TzEfHmrXTOcyPiXwfZ3xkR7xmG%0A85wZEXdu6XGkbYGBrVGrv1/6fX+BZ+YbM/OOOsdpjYj1ETFaf16+BHw8M3fLzPv77qy+9xeqQH8y%0AIi6KiO225ISZeX5mfnSwItVLUmW0/gKSYPh/6ccwHuv3B40Y34zjNnjuAKYBD9Ypekhm7ga8GzgB%0A+Itm103SxgxsjTUbBXjVCz+qWn5bRNwbEc9FxIqI+FJVbEMPvLvqZb49aj5Xvb8rIhZExMRex/3z%0AiHgsIp7uVW7Dedoj4rsRcVlEPAfMiYi3RsSPI2JVRPw6Iv4pIrbvdbz1EfGXEfGLiFgdEX8bEdOr%0A93RHxFW9y/f5Hvuta0TsCDwPjAfuj4hf1G28zF8CdwEH9Tr+cRGxtKr7XRHxpl77Ph0RT1R1frhP%0AG1zWq9wZvdrrM33q/62I+Hyv9baIeLzX+jkR8Wh1jmURMXuQdvhK1QbPRcTPIuLget+ztK0wsDXa%0A9e0V913vHeD/CHwlM3cHXgtcU21/V/V192r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+ewHnOkedOZJG2muXPb6e5u3vEnTYL589sbKtva2srKlSsZP348%0Au+66K0cffTQXX3wxEydO3Ozzn3baaZx22mkD7o+IEb17/swzz2S//fbj85///Cb7nn/++RGoUXMZ%0A2JK0mbq7obW1vWnH7+xs/NgRwQ033MBRRx1FV1cX733ve/m7v/s7vvjFvhNVjh4j/QdDX6+88grb%0Abde8WHVIXJJGmZaWFo455hiWLVvWs+3uu+/mHe94B3vssQczZszgRz/6Uc++b33rW0yfPp2JEyfy%0A2te+liuuuKJn+7ve9a6ecosWLeLAAw9k0qRJnH322Rs95tbe3s4ZZ5zRs97Z2cm4ceNYv349AJde%0AeikHHXQQEydOZPr06XzjG98YsP4XXngh++67LxMnTuTAAw/k9ttvH7DsQI/ajRs3jl/96ldArSd+%0A1llncdxxxzFx4kQOP/zwnn0ADz/8MEcffTR77bUXBx54INdcc03PvhtvvJFDDz2U3XffnWnTpjFv%0A3rxNvsdvfvObvOY1r2HmzObO2G1gS9IosSG8nnjiCW655Rbe/va3A/Dkk09y3HHHcd5557Fq1Sq+%0A9KUvceKJJ/LMM8/w4osv8olPfIJbbrmF1atX8+Mf/5gZM2Zscuynn36aE088kS984Qs888wzTJ8+%0Anbvuuqtnf72ebktLCzfeeCOrV6/m0ksv5ZOf/CT33XffJuUeeeQRLr74Yu69915Wr17NwoULaW1t%0A3YJWqbn66qtpb29n1apVvO51r+Ozn/0sAC+++CJHH300p59+Or/5zW+46qqr+PjHP85DDz0EwIQJ%0AE7j88st57rnnuPHGG/na177Gddddt9Gx77jjDh5++GFuvfXWLa7nYAxsSRoFMpPZs2czceJEpk2b%0AxvTp0/nc5z4HwOWXX86sWbM49thjAZg5cyaHHXYYN954IxHBuHHjeOCBB/jtb39LS0sLBx100CbH%0Av+mmm3jjG9/ICSecwPjx45k7dy5TpkzZ6PyDmTVrFvvvvz8A7373uznmmGO48847Nyk3fvx41qxZ%0Aw7Jly1i3bh3Tpk3jta997Wa3C9T+mDjhhBM47LDDGD9+PKeddhpLly4F4IYbbmD//fdnzpw5jBs3%0AjhkzZnDCCSf09LKPOOIIDj74YADe9KY3ccopp2w0OgG10YWdd96ZHXfccYvqWY+BLUmjQERw3XXX%0AsXr1ajo6Orj99tu59957AXjssce45ppr2GOPPXped911FytWrGCXXXbh6quv5l/+5V/Ye++9Oe64%0A43jkkUc2Of6vf/1r9t133422DeXO7ptvvpnDDz+cvfbaiz322IObbrqJZ555ZpNyr3vd65g/fz7t%0A7e20tLRw6qmn8tRTTw2xNTbV0tLSs7zzzjvzwgsvALW2ueeeezZqmyuuuIKuri4A7rnnHo488khe%0A/epXM2nSJL7+9a9vUu/hvsN9IAa2JI0y7373uzn77LP59Kc/DcC0adM444wzWLVqVc/r+eef51Of%0A+hQAxxxzDAsXLmTFihUceOCBfPSjH93kmHvvvTePP/54z3pmbrQ+YcIEXnrppZ71FStW9CyvWbOG%0AE088kU996lOsXLmSVatWMWvWrAF75aeeeip33nknjz32GBHR8330Z0tvOps2bRpHHHHEJm1z8cUX%0AA/ChD32I2bNn88QTT9Dd3c3HPvaxnuvyw1WHRhnYkjQKzZ07lyVLlnDPPfdw+umn84Mf/ICFCxfy%0Au9/9jpdffpmOjg6efPJJVq5cyXXXXceLL77I9ttvz6677sr48eM3Od6sWbNYtmwZ3//+93nllVe4%0A6KKLNgrlGTNmcMcdd/D444/z3HPPcf755/fsW7t2LWvXrmXy5MmMGzeOm2++mYULF/Zb7+XLl3P7%0A7bezZs0adtxxR3baaad+6wO1PxpeeeUVXn755Z7XunXr+i03kPe9730sX76cyy+/nHXr1rFu3Tp+%0A8pOf8PDDDwPwwgsvsMcee7DDDjuwZMkSrrjiihG7M93AlqRRaPLkycyZM6fnjuvrrruOL3zhC7z6%0A1a9m2rRpfPnLXyYzWb9+PV/5ylfYZ5992Guvvbjzzjv52te+Bmz82NTkyZO55pprOOecc5g8eTKP%0APvoo73znO3vON3PmTE4++WQOOeQQ3vrWt/L+97+/57277bYbF110ESeddBJ77rknV155JR/4wAc2%0Aqu+G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wfVGU+%0AC6zNzMFmJvGOtzoaaesG2dZbzjYcQZmZzu0wvCJiAvA94BOZ+XzE7x8Ltr2HVzXyPKO6r+vWiDiy%0Az/667b1ZgZ2ZRw+2PyLOBGZRe0Z7gyeB/Xqt71tt0yDqtfUAbOvm6Nuu+7HxSIaGX1dETMnMFREx%0AFVg50hUaLSJie2phfVlmXltttr2bLDOfi4gbgT9kiO3djLvEjwX+GvhAdaF9g+uBUyJih4jYH3g9%0AtclWNDx6z5hjWzfHvcDrI6I1InagdmPf9SNcp9HuemBOtTwHuHaQsmpQ1LrSlwAPZub8Xrts7yaI%0AiMkb7gCPiJ2Bo4H7GGJ7D/tz2BHxC2oX1Z+tNv04Mz9e7fsMtevar1Abgrl1WE8+xkTEnwIXAZOB%0A54D7MvNPqn22dRNExJ/w+8+AvyQzzx/hKo0aEXElcAS1/89dwHnAdcB3gGlAJ3BSZtb5QEbVU92h%0AfAfwM35/qedcan/Y297DLCLeRO2msnHV67LM/IeI2JMhtLcTp0iSVACfzZUkqQAGtiRJBTCwJUkq%0AgIEtSVIBDGxJkgpgYEuSVAADW5KkAhjYkiQV4P8D6ozDoP/R7QEAAAAASUVORK5CYII=">
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>让我们看看相关系数：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [6]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lr</span><span class="o">.</span><span class="n">coef_</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[6]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>array([ -1.07170557e-01,   4.63952195e-02,   2.08602395e-02,
         2.68856140e+00,  -1.77957587e+01,   3.80475246e+00,
         7.51061703e-04,  -1.47575880e+00,   3.05655038e-01,
        -1.23293463e-02,  -9.53463555e-01,   9.39251272e-03,
        -5.25466633e-01])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<blockquote>
<p>一个常用的特征与对应的相关系数的呈现方式是用<code>zip</code>函数（Python 2.x用<code>zip</code>，Python 3.x里<code>zip</code>返回生成器，必须用<code>list(zip(...))</code>），这里是<code>zip(boston.feature_names, lr.coef_)</code>。</p>
</blockquote>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [7]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">list</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">feature_names</span><span class="p">,</span> <span class="n">lr</span><span class="o">.</span><span class="n">coef_</span><span class="p">))</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[7]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>[('CRIM', -0.10717055656035571),
 ('ZN', 0.046395219529794252),
 ('INDUS', 0.020860239532177083),
 ('CHAS', 2.6885613993179542),
 ('NOX', -17.795758660309406),
 ('RM', 3.8047524602580065),
 ('AGE', 0.0007510617033257283),
 ('DIS', -1.4757587965198153),
 ('RAD', 0.30565503833909768),
 ('TAX', -0.012329346305270588),
 ('PTRATIO', -0.95346355469056121),
 ('B', 0.0093925127221890746),
 ('LSTAT', -0.52546663290078754)]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>这样我们就可以看出哪个因素与因变量是负相关，哪个因素与因变量是正相关了。例如，上面的结果显示，波士顿地区的犯罪率与房价负相关。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="How-it-works...">How it works...<a class="anchor-link" href="fitting-a-line-through-data.html#How-it-works...">¶</a>
</h3>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>线性回归的基本理念是找出满足$y=X\beta$的相关系数集合$\beta$，其中$X$是因变量数据矩阵。想找一组完全能够满足等式的相关系数很难，因此通常会增加一个误差项表示不精确程度或测量误差。因此，方程就变成了$y=X\beta+\epsilon$，其中$\epsilon$被认为是服从正态分布且与$X$独立的随机变量。用几何学的观点描述，就是说这个变量与$X$是正交的（perpendicular）。这超出了本书的范围，可以参考其他信息证明$E(X\epsilon)=0$。</p>
<p>为了找到相关系数集合$\beta$，我们最小化误差项，这转化成了残差平方和最小化问题。</p>
<p>这个问题可以用解析方法解决，其解是$\beta=(X^TX)^{-1}X^T \hat y$</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h4 id="There's-more...">There's more...<a class="anchor-link" href="fitting-a-line-through-data.html#There's-more...">¶</a>
</h4>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><code>LinearRegression</code>对象可以自动标准正态化（normalize或scale）输入数据：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [8]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">lr2</span> <span class="o">=</span> <span class="n">LinearRegression</span><span class="p">(</span><span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">lr2</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">data</span><span class="p">,</span> <span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[8]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=True)</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [9]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">predictions2</span> <span class="o">=</span> <span class="n">lr2</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [10]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">matplotlib</span> inline
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="k">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="n">f</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
<span class="n">f</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="o">-</span><span class="n">predictions2</span><span class="p">,</span><span class="n">bins</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">'Residuals Linear'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'b'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=.</span><span class="mi">5</span><span class="p">);</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s2">"Histogram of Residuals"</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s1">'best'</span><span class="p">);</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt"></div>


<div class="output_png output_subarea ">
<img src="%0AAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucnVV97/HPL+FOCAGik3CJg1GKoBgsKrUqAwakETEF%0Ay0WgwePLvqwcajznVEE9dFJbAasvU1q02iKmIBfRCsg1OeAIoUKkEsRwiegZDiCZCGQIF0mC+Z0/%0A9pNxMpmZvSeZncma+bxfr/2a57L286xZycx31nqeZ+3ITCRJ0rZt3EhXQJIk1WdgS5JUAANbkqQC%0AGNiSJBXAwJYkqQAGtiRJBTCwNaZFxM8j4t0jXY+RFBF/GhGPR8TzEfHmrXTOcyPiXwfZ3xkR7xmG%0A85wZEXdu6XGkbYGBrVGrv1/6fX+BZ+YbM/OOOsdpjYj1ETFaf16+BHw8M3fLzPv77qy+9xeqQH8y%0AIi6KiO225ISZeX5mfnSwItVLUmW0/gKSYPh/6ccwHuv3B40Y34zjNnjuAKYBD9Ypekhm7ga8GzgB%0A+Itm103SxgxsjTUbBXjVCz+qWn5bRNwbEc9FxIqI+FJVbEMPvLvqZb49aj5Xvb8rIhZExMRex/3z%0AiHgsIp7uVW7Dedoj4rsRcVlEPAfMiYi3RsSPI2JVRPw6Iv4pIrbvdbz1EfGXEfGLiFgdEX8bEdOr%0A93RHxFW9y/f5Hvuta0TsCDwPjAfuj4hf1G28zF8CdwEH9Tr+cRGxtK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7KZx5ckqUQRQQ7xprO6Q+KSpNovWGlz%0ADFfH1cCWpAY5YqihGs4/9LyGLUlSAQxsSZIKYGBLklQAA1uS1K9vf/vbvPe97x1wf1tbG5dccskW%0An6ejo4P99ttvi4/T22677UZnZ+ewHnOkedOZJG2muXPb6e5u3vEnTYL589sbKtva2srKlSsZP348%0Au+66K0cffTQXX3wxEydO3Ozzn3baaZx22mkD7o+IEb17/swzz2S//fbj85///Cb7nn/++RGoUXMZ%0A2JK0mbq7obW1vWnH7+xs/NgRwQ033MBRRx1FV1cX733ve/m7v/s7vvjFvhNVjh4j/QdDX6+88grb%0Abde8WHVIXJJGmZaWFo455hiWLVvWs+3uu+/mHe94B3vssQczZszgRz/6Uc++b33rW0yfPp2JEyfy%0A2te+liuuuKJn+7ve9a6ecosWLeLAAw9k0qRJnH322Rs95tbe3s4ZZ5zRs97Z2cm4ceNYv349AJde%0AeikHHXQQEydOZPr06XzjG98YsP4XXngh++67LxMnTuTAAw/k9ttvH7DsQI/ajRs3jl/96ldArSd+%0A1llncdxxxzFx4kQOP/zwnn0ADz/8MEcffTR77bUXBx54INdcc03PvhtvvJFDDz2U3XffnWnTpjFv%0A3rxNvsdvfvObvOY1r2HmzObO2G1gS9IosSG8nnjiCW655Rbe/va3A/Dkk09y3HHHcd5557Fq1Sq+%0A9KUvceKJJ/LMM8/w4osv8olPfIJbbrmF1atX8+Mf/5gZM2Zscuynn36aE088kS984Qs888wzTJ8+%0Anbvuuqtnf72ebktLCzfeeCOrV6/m0ksv5ZOf/CT33XffJuUeeeQRLr74Yu69915Wr17NwoULaW1t%0A3YJWqbn66qtpb29n1apVvO51r+Ozn/0sAC+++CJHH300p59+Or/5zW+46qqr+PjHP85DDz0EwIQJ%0AE7j88st57rnnuPHGG/na177Gddddt9Gx77jjDh5++GFuvfXWLa7nYAxsSRoFMpPZs2czceJEpk2b%0AxvTp0/nc5z4HwOWXX86sWbM49thjAZg5cyaHHXYYN954IxHBuHHjeOCBB/jtb39LS0sLBx100CbH%0Av+mmm3jjG9/ICSecwPjx45k7dy5TpkzZ6PyDmTVrFvvvvz8A7373uznmmGO48847Nyk3fvx41qxZ%0Aw7Jly1i3bh3Tpk3jta997Wa3C9T+mDjhhBM47LDDGD9+PKeddhpLly4F4IYbbmD//fdnzpw5jBs3%0AjhkzZnDCCSf09LKPOOIIDj74YADe9KY3ccopp2w0OgG10YWdd96ZHXfccYvqWY+BLUmjQERw3XXX%0AsXr1ajo6Orj99tu59957AXjssce45ppr2GOPPXped911FytWrGCXXXbh6quv5l/+5V/Ye++9Oe64%0A43jkkUc2Of6vf/1r9t133422DeXO7ptvvpnDDz+cvfbaiz322IObbrqJZ555ZpNyr3vd65g/fz7t%0A7e20tLRw6qmn8tRTTw2xNTbV0tLSs7zzzjvzwgsvALW2ueeeezZqmyuuuIKuri4A7rnnHo488khe%0A/epXM2nSJL7+9a9vUu/hvsN9IAa2JI0y7373uzn77LP59Kc/DcC0adM444wzWLVqVc/r+eef51Of%0A+hQAxxxzDAsXLmTFihUceOCBfPSjH93kmHvvvTePP/54z3pmbrQ+YcIEXnrppZ71FStW9CyvWbOG%0AE088kU996lOsXLmSVatWMWvWrAF75aeeeip33nknjz32GBHR8330Z0tvOps2bRpHHHHEJm1z8cUX%0AA/ChD32I2bNn88QTT9Dd3c3HPvaxnuvyw1WHRhnYkjQKzZ07lyVLlnDPPfdw+umn84Mf/ICFCxfy%0Au9/9jpdffpmOjg6efPJJVq5cyXXXXceLL77I9ttvz6677sr48eM3Od6sWbNYtmwZ3//+93nllVe4%0A6KKLNgrlGTNmcMcdd/D444/z3HPPcf755/fsW7t2LWvXrmXy5MmMGzeOm2++mYULF/Zb7+XLl3P7%0A7bezZs0adtxxR3baaad+6wO1PxpeeeUVXn755Z7XunXr+i03kPe9730sX76cyy+/nHXr1rFu3Tp+%0A8pOf8PDDDwPwwgsvsMcee7DDDjuwZMkSrrjiihG7M93AlqRRaPLkycyZM6fnjuvrrruOL3zhC7z6%0A1a9m2rRpfPnLXy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Btwqt9sL2bJjNfqhZ3oHbf1yqG2N7N7nX9N+CmanlvapOrbOBEK81jWzeHkwVt%0AfS2Z2VUtdwEtI1mZ0SgiWoFDqXWwbO8miYhxEbGUWrv+MDOXMcT23qy7xCNiETCln12fycwfVGU+%0AC6zNzMFmJvGOtzoaaesG2dZbzjYcQZmZzu0wvCJiAvA94BOZ+XzE7x8Ltr2HVzXyPKO6r+vWiDiy%0Az/667b1ZgZ2ZRw+2PyLOBGZRe0Z7gyeB/Xqt71tt0yDqtfUAbOvm6Nuu+7HxSIaGX1dETMnMFREx%0AFVg50hUaLSJie2phfVlmXltttr2bLDOfi4gbgT9kiO3djLvEjwX+GvhAdaF9g+uBUyJih4jYH3g9%0AtclWNDx6z5hjWzfHvcDrI6I1InagdmPf9SNcp9HuemBOtTwHuHaQsmpQ1LrSlwAPZub8Xrts7yaI%0AiMkb7gCPiJ2Bo4H7GGJ7D/tz2BHxC2oX1Z+tNv04Mz9e7fsMtevar1Abgrl1WE8+xkTEnwIXAZOB%0A54D7MvNPqn22dRNExJ/w+8+AvyQzzx/hKo0aEXElcAS1/89dwHnAdcB3gGlAJ3BSZtb5QEbVU92h%0AfAfwM35/qedcan/Y297DLCLeRO2msnHV67LM/IeI2JMhtLcTp0iSVACfzZUkqQAGtiRJBTCwJUkq%0AgIEtSVIBDGxJkgpgYEuSVAADW5KkAhjYkiQV4P8D6ozDoP/R7QEAAAAASUVORK5CYII=">
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [11]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [14]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="o">-</span><span class="n">predictions2</span><span class="p">,</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mi">99</span><span class="p">])</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[14]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>array([ -6.68134034,  15.32488183])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [15]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">np</span><span class="o">.</span><span class="n">percentile</span><span class="p">(</span><span class="n">boston</span><span class="o">.</span><span class="n">target</span><span class="o">-</span><span class="n">predictions</span><span class="p">,</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mi">99</span><span class="p">])</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">
<div class="prompt output_prompt">Out[15]:</div>


<div class="output_text output_subarea output_execute_result">
<pre>array([ -6.68134034,  15.32488183])</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>与前面的结果没有不同。</p>

</div>
</div>
</div>
    </div>
  </div>

    </div>
    <aside class="postpromonav"><nav><ul itemprop="keywords" class="tags">
<li><a class="tag p-category" href="../categories/chs.html" rel="tag">CHS</a></li>
            <li><a class="tag p-category" href="../categories/ipython.html" rel="tag">ipython</a></li>
            <li><a class="tag p-category" href="../categories/machine-learning.html" rel="tag">Machine Learning</a></li>
            <li><a class="tag p-category" href="../categories/python.html" rel="tag">Python</a></li>
            <li><a class="tag p-category" href="../categories/scikit-learn-cookbook.html" rel="tag">scikit-learn cookbook</a></li>
        </ul>
<ul class="pager hidden-print">
<li class="previous">
                <a href="optimizing-the-ridge-regression-parameter.html" rel="prev" title="optimizing-the-ridge-regression-parameter">Previous post</a>
            </li>
            <li class="next">
                <a href="evaluating-the-linear-regression-model.html" rel="next" title="evaluating-the-linear-regression-model">Next post</a>
            </li>
        </ul></nav></aside><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
    },
    displayAlign: 'center', // Change this to 'center' to center equations.
    "HTML-CSS": {
        styles: {'.MathJax_Display': {"margin": 0}}
    }
});
</script></article>
</div>
        <!--End of body content-->

        <footer id="footer">
            Contents © 2017         <a href="mailto:muxuezi@gmail.com">Tao Junjie</a> - Powered by         <a href="https://getnikola.com" rel="nofollow">Nikola</a>         
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0">
<img alt="Creative Commons License BY-NC-SA" style="border-width:0; margin-bottom:12px;" src="http://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png"></a>
            
        </footer>
</div>
</div>


            <script src="../assets/js/all-nocdn.js"></script><script>$('a.image-reference:not(.islink) img:not(.islink)').parent().colorbox({rel:"gal",maxWidth:"100%",maxHeight:"100%",scalePhotos:true});</script><!-- fancy dates --><script>
    moment.locale("en");
    fancydates(0, "YYYY-MM-DD HH:mm");
    </script><!-- end fancy dates --><script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-51330059-1', 'auto');
  ga('send', 'pageview');

</script>
</body>
</html>
